package com.github.permissiondog.cancanpandroid.repository.impl;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.github.permissiondog.cancanpandroid.MyApplication;



public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    private static MySQLiteOpenHelper INSTANCE = null;
    public static synchronized MySQLiteOpenHelper getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new MySQLiteOpenHelper(MyApplication.getInstance());
        }
        return INSTANCE;
    }
    private MySQLiteOpenHelper(Context context) {
        super(context, "data.db", null, 1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        var CREATE_COOKIES_TABLE = """
                    CREATE TABLE cookies (
                        name TEXT PRIMARY KEY NOT NULL,
                        value TEXT NOT NULL,
                        domain TEXT NOT NULL,
                        path TEXT NOT NULL,
                        expiresAt INTEGER NOT NULL,
                        secure INTEGER NOT NULL,
                        httpOnly INTEGER NOT NULL
                    )
                """;
        var CREATE_PREFERENCES_TABLE = """
                CREATE TABLE preferences (
                    `key` TEXT PRIMARY KEY NOT NULL,
                    `value` TEXT
                )
                """;

        db.execSQL(CREATE_COOKIES_TABLE);
        db.execSQL(CREATE_PREFERENCES_TABLE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
